package xyz.sicau.blog.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import xyz.sicau.blog.bean.Note;

import java.util.List;

public interface NoteMapper {

    /**
     * 分页查询
     * @param start 从第条记录开始
     * @param page 查询多少条记录
     */
    @Select("select * from note where note_userid=#{userId} AND note_type in ('','public') order by note_time desc limit #{start} , #{page}")
    List<Note> getNotePage(int start, int page, int userId);
    // 不分页
    @Select("select * from note where note_userid=#{userId} AND note_type in ('','public') order by note_time desc")
    List<Note> getNotes(int userId);

    List<Note> getNotesShare(String[] ids);
    List<Note> getNotePageShare(int start, int page, String[] ids);

    /**
     * 插入笔记
     */
    // 这是不带time的
    int insertNote(Note note);

    // 按照id删日记, userid用来校验
    @Delete("DELETE FROM `note` WHERE note_id=#{blogId} and note_userid=#{userId}")
    int deleteNote(int blogId, int userId);

    // 修改数据=========================================================
    int updateNote(Note note);

    // 批量修改type
    int updateNoteTypes(String[] ids, String value, int userId);


    // Tags =====本质是type为tag的note==============================
    // 根据用户名，查询全部tags
    @Select("select * from note where note_type = 'tag' AND note_userid=#{userId} order by note_time desc")
    List<Note> getTagsAll(String userId);

    // Todos =====本质是type为todo的note==============================
    // 根据用户名，查询全部todo
    @Select("select * from note where note_type = 'todo' AND note_userid=#{userId} order by note_time desc")
    List<Note> getTodosAll(String userId);

}
